//
// Created by wkm on 2024-03-17.
//

#include "FiniteFieldMul.h"

//定义轮常量表
const unsigned char Rcon[10] = {
        0x01, 0x02, 0x04, 0x08, 0x10,
        0x20, 0x40, 0x80, 0x1b, 0x36
};

//定义有限域*2乘法
unsigned char x2time(unsigned char x) {
    if (x & 0x80) {
        return (((x << 1) ^ 0x1B) & 0xFF);
    }
    return x << 1;
}

//定义有限域*3乘法
unsigned char x3time(unsigned char x) {
    return (x2time(x) ^ x);
}

//定义有限域*4乘法
unsigned char x4time(unsigned char x) {
    return (x2time(x2time(x)));
}

//定义有限域*8乘法
unsigned char x8time(unsigned char x) {
    return (x2time(x2time(x2time(x))));
}

//定义有限域*9乘法
unsigned char x9time(unsigned char x) {
    return (x8time(x) ^ x);
}

//定义有限域*B乘法
unsigned char xBtime(unsigned char x) {
    return (x8time(x) ^ x2time(x) ^ x);
}

//定义有限域*D乘法
unsigned char xDtime(unsigned char x) {
    return (x8time(x) ^ x4time(x) ^ x);
}

//定义有限域*E乘法
unsigned char xEtime(unsigned char x) {
    return (x8time(x) ^ x4time(x) ^ x2time(x));
}
